var vm=new Vue({
    el:"#goodsOrder",
    data:{
        List:[],//查询结果集
        pageSize:5,//每页显示数量
        goodsOrder:{},//查询条件集
        GoodsOrder:{},//根据id查到的结果
        addGoodsOrder:{},//添加知识绑定的对象
        selectIds:[]//选中的ID集合
    },
    mounted(){
        //初始化页面加载的方法
        this.selectPage(1);
        this.getPageData();
    },
    methods:{
        //条件查询并分页
        selectPage:function (pageNum){
            let that=this;
            axios.post("/goodsOrder/selectPage.do?pageNum="+pageNum+"&pageSize="+this.pageSize,this.goodsOrder).then(function (response){
                that.List=response.data;
            })
        },
        //根据id删除
        deleteByPrimaryKey:function (orderid){
            let that=this;
            axios.get("/goodsOrder/deleteByPrimaryKey.do?orderids="+orderid).then(function (response){
                that.selectPage(1);
            })
        },
        //更新复选
        updateSelection:function($event, id) {
            if($event.target.checked){//如果是被选中,则增加到数组
                this.selectIds.push( id);
            }else{
                let idx = this.selectIds.indexOf(id);//获取当前选中的id在数组中的下标
                this.selectIds.splice(idx, 1);//删除
            }
        },
        //根据id批量删除
        deleteByIds:function (){
            let that=this;
            axios.get("/goodsOrder/deleteById.do?orderids="+this.selectIds).then(function (response){
                that.selectPage(1);
            })
            this.selectIds=[];
        },
        //根据id查询
        selectByPrimaryKey:function (orderid){
            let that=this;
            axios.get("/goodsOrder/selectByPrimaryKey.do?orderid="+orderid).then(function (response){
                that.GoodsOrder=response.data;
                localStorage.setItem('GoodsOrder',JSON.stringify(that.GoodsOrder));//将查询的结果存入本地缓存
            })
        },
        //修改
        updateByPrimaryKey:function (){
            let that=this;
            axios.post("/goodsOrder/updateByPrimaryKey.do",this.GoodsOrder).then(function (response){
                if (response.data.success){
                    localStorage.removeItem('GoodsOrder');//清除本地缓存中的Knowledge
                    alert(response.data.message)
                }else {
                    alert(response.data.message)
                }
            })
        },
        //刷新页面或者从别的页面进入，提取this.Knowledge的值
        getPageData:function (){
            this.GoodsOrder=JSON.parse(localStorage.getItem('GoodsOrder'));
            if (this.GoodsOrder==null){
                this.GoodsOrder={};
            }
        },
        //新增
        insert:function (){
            let  that=this;
            axios.post("/goodsOrder/insert.do",this.addGoodsOrder).then(function (response){
                if (response.data.success){
                    alert(response.data.message)
                }else {
                    alert(response.data.message)
                }
            })
        }

    }
})